<?php
	session_start();
	
	if (!isset($_SESSION['sesi_login']))
		header("Location:../../index.php");
	
	@chdir("../../");
	define('ABS_URL',str_replace("\\","/",getcwd()));
	require ABS_URL.'/engine/Smarty.class.php';
	require ABS_URL."/functions/class.query.inc.php";
	$smarty = new Smarty();
	require ABS_URL."/dev_con.inc.php";
	require ABS_URL."/functions/func_file.php";
	$queryData = new queryData();
	$queryData->baseConfig();
	require ABS_URL."/functions/func_content.php";
	require ABS_URL."/langs/".BASE_LANGUAGE.'.inc.php';
	require $queryData->get_curr_dir(dirname(__FILE__))."/langs/".BASE_LANGUAGE.'.inc.php';
	
	$event = trim($_POST['nama_event']);
	$deskripsi = trim($_POST['isi']);
	$tanggal1 = strip_tags($_POST['tanggal1']);
	$tanggal = date("Y-m-d H:i:s");
	$tanggal2 = strip_tags($_POST['tanggal2']);
	$eventData = $tanggal1.'[break]'.$tanggal2;
	$status = $_POST['status'];
	if ($_POST['publish']=="ya") {
		$status = 1;
	} else {
		$status = 0;
	}
	
	$author = strtolower($_SESSION['author']);
	
	if (strtolower(ACT_VER)=="hapus") {
		$kode = (int) $_GET['kode'];
		$sql = "DELETE FROM tbl_content WHERE idx='".$kode."' AND tipe='event'";
		$qry = mysql_query($sql);
		$act = "hapus";
		($qry) ? $_SESSION['sesi_ver'] = $queryData->cekAksi($kode,'delete') : $_SESSION['sesi_ver'] = '';
		$act = 'lihat';
	} else {
		$a = array($event,$deskripsi);
		$b = array('empty','empty');
		$c = array($EVENT_TITLE,$EVENT_CONTENT);
		switch (strtolower($_POST['act_ver'])) {
			case "input" :
				$result = $queryData->NotificationCheck($a,$b,$c);
				if (empty($result)) {
					$sql = "INSERT INTO tbl_content VALUES(NULL,'".$event."','".$eventData."','".$deskripsi."','".$author."','".$tanggal."','event','".$status."')";
					$qry = mysql_query($sql);
					$_SESSION['sesi_ver'] = $queryData->cekAksi($event,'add');
					$act = 'lihat';
				} else {
					$_SESSION['sesi_ver'] = $DEV_ACTION_NOTIFICATION;
					foreach($result as $data) {
						$_SESSION['sesi_ver'] .= '<br />- '.$data;
					}
					$act = 'tambah';
				}
			break;
			case "edit" :
				$kode = (int) $_POST['kode'];
				$result = $queryData->NotificationCheck($a,$b,$c);
				if (empty($result)) {
					$sql = "UPDATE tbl_content SET judul='".$event."', header_c='".$eventData."', isi='".$deskripsi."', tanggal='".$tanggal."', status='".$status."' WHERE idx='".$kode."'";
					$qry = mysql_query($sql);
					$_SESSION['sesi_ver'] = $queryData->cekAksi($event,'edit');
					$act = 'lihat';
				} else {
					$_SESSION['sesi_ver'] = $DEV_ACTION_NOTIFICATION;
					foreach($result as $data) {
						$_SESSION['sesi_ver'] .= '<br />- '.$data;
					}								
					$act = 'edit&kode='.$kode;
				}
			break;
		};
	};
	
	if (isset($_SESSION['sesi_login'])) {
		header('Location:../../?show='.SHOW.'&showview='.SHOWVIEW.'&act='.$act.'&limitdown=0');
	} else {
		header("Location:../../index.php");
	};
?>